package tps.video_games;

import java.awt.Color;

import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.GameScene;
import com.uqbar.vainilla.appearances.Circle;
import com.uqbar.vainilla.appearances.Rectangle;

public class Ladrillo extends GameComponent<GameScene> {
	private int width = 70;
	private int height = 30;
	private Pildora pildora = null;
	private int resistencia = 1;
	private int puntos = 10;
	
	public Ladrillo(int x,int y,Color color) {
		super(x,y);
		this.setAppearance(new Rectangle(color, this.width, this.height));
	} 
	
	
	public Ladrillo(int x, int y, Color color, Pildora p) {
		super(x,y);
		this.setAppearance(new Rectangle(color, this.width, this.height));
		this.pildora = p;
		this.pildora.setX(x);
		this.pildora.setY(y);
	}
	
	public Ladrillo(int x, int y, Color color, int r) {
		super(x,y);
		this.setAppearance(new Rectangle(color, this.width, this.height));
		this.resistencia = r;
		this.puntos = r*10;
	}
	
	public Ladrillo(int x, int y, Color color,int r,Pildora p) {
		super(x,y);
		this.setAppearance(new Rectangle(color, this.width, this.height));
		this.resistencia = r;
		this.puntos = r*10;
		this.pildora = p;
		this.pildora.setX(x);
		this.pildora.setY(y);
	}
	
	public int getWidth() {
		return width;
	}
	
	public int getHeight() {
		return height;
	}
	
	public void recibirGolpe(){
		this.resistencia--;
		if(this.esDestruido()){
			this.liberarPildora();
			((Arkanoid)this.getGame()).sumarPuntos(this.puntos);
			this.destroy();			
		}
	}
	
	public void liberarPildora() {
		if(this.pildora != null)
			this.getGame().getCurrentScene().addComponent(this.pildora);
		
	}
	
	public boolean esDestruido(){
		return this.resistencia == 0;
	}
	
	public int getPuntos() {
		return puntos;
	}

}
